import Vue from "vue";
import Router from "vue-router";
import LoginLayout from "@/views/login/layout/LoginLayout";
// import test from '@/views/test'

Vue.use(Router);
import Layout from "@/layout";
import WebLayout from "@/layout/WebLayout";

import courseRouter from "./modules/course";

// 静态通用路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path*",
        component: () => import("@/views/redirect/index"),
      },
    ],
  },
  {
    path: "#",
    component: LoginLayout,
    redirect: "/login",
    hidden: true,
    children: [
      {
        path: "/login",
        name: "Login",
        component: () => import("@/views/login/index"),
        meta: {
          title: "用户登录",
        },
      },
      {
        path: "/register",
        name: "Register",
        layout: LoginLayout,
        component: () => import("@/views/login/register"),
        meta: {
          title: "学员注册",
        },
      },
      {
        path: "/forgot",
        name: "Forgot",
        layout: LoginLayout,
        component: () => import("@/views/login/forgot"),
        meta: {
          title: "忘记密码",
        },
      },
    ],
  },

  {
    path: "/help",
    name: "Help",
    component: () => import("@/views/login/help"),
    meta: {
      title: "帮助中心",
      icon: "guide",
      noCache: true,
    },
    metaTitle: "帮助中心",
    menuType: 1,
    parentId: 0,
  },

  {
    path: "/sync",
    name: "LoginSync",
    component: () => import("@/views/login/sync"),
    hidden: true,
    meta: { title: "登录成功", noCache: true },
  },

  {
    path: "/404",
    component: () => import("@/views/error-page/404"),
    hidden: true,
  },

  {
    path: "/401",
    component: () => import("@/views/error-page/401"),
    hidden: true,
  },

  {
    path: "/web/exam/start/:id",
    component: () => import("@/views/web/exam/exam"),
    name: "StartExam",
    meta: { title: "开始考试", noCache: true, activeMenu: "/web/index" },
    hidden: true,
  },

  {
    path: "/web/exam/debug",
    component: () => import("@/views/web/exam/debug"),
    name: "DeviceDebug",
    meta: { title: "设备调试", noCache: true, activeMenu: "/web/index" },
    hidden: true,
  },

  {
    path: "/profile",
    component: Layout,
    redirect: "/profile/index",
    hidden: true,
    children: [
      {
        path: "index",
        component: () => import("@/views/profile/index"),
        name: "Profile",
        meta: { title: "个人资料", icon: "user", noCache: true },
      },
    ],
  },

  {
    path: "/",
    component: WebLayout,
    hidden: true,
    children: [
      {
        path: "/web/index",
        component: () => import("@/views/web/exam/list"),
        name: "ExamOnline",
        meta: { title: "在线考试", noCache: true },
      },

      {
        path: "/web/exam/check/:id",
        component: () => import("@/views/web/exam/check"),
        name: "CheckExam",
        meta: { title: "考试校验", noCache: true, activeMenu: "/web/index" },
      },

      {
        path: "/web/exam/result/:id",
        component: () => import("@/views/web/exam/result"),
        name: "ShowExam",
        meta: { title: "考试结果", noCache: true, activeMenu: "/web/index" },
      },

      {
        path: "/web/qu/view/:id",
        component: () => import("@/views/web/qu/view"),
        name: "ViewQu",
        meta: { title: "试题详情", noCache: true, activeMenu: "/web/paper" },
      },

      {
        path: "/web/uc",
        component: () => import("@/views/web/ucenter"),
        name: "UserCenter",
        meta: { title: "用户中心", noCache: true, activeMenu: "/web/uc" },
      },

      {
        path: "/web/notice",
        component: () => import("@/views/web/notice"),
        name: "NoticeList",
        meta: { title: "系统公告", noCache: true },
      },
      {
        path: "/web/notice/detail/:id",
        component: () => import("@/views/web/notice/detail"),
        name: "NoticeDetail",
        meta: { title: "公告详情", noCache: true, activeMenu: "/web/notice" },
      },
      {
        path: "/web/paper",
        component: () => import("@/views/web/paper/total"),
        name: "ListMyExam",
        meta: { title: "我的成绩", noCache: true, activeMenu: "/web/uc" },
      },

      {
        path: "/web/paper/list/:examId/:userId",
        component: () => import("@/views/web/paper/list"),
        name: "WebPaperList",
        meta: { title: "考试记录", noCache: true, activeMenu: "/web/uc" },
      },

      {
        path: "/web/book/list/:examId",
        component: () => import("@/views/web/book"),
        name: "BookList",
        meta: { title: "考试错题", noCache: true, activeMenu: "/web/uc" },
      },

      {
        path: "/web/repo",
        component: () => import("@/views/web/repo"),
        name: "MyRepoList",
        meta: { title: "题库练习", noCache: true },
      },

      {
        path: "/web/repo/view/:repoId",
        component: () => import("@/views/web/repo/view"),
        name: "MyRepoView",
        meta: { title: "题库详情", noCache: true, activeMenu: "/web/repo" },
      },

      {
        path: "/web/repo/training/:repoId/:mode",
        component: () => import("@/views/web/repo/training"),
        name: "MyRepoTraining",
        meta: { title: "开始训练", noCache: true, activeMenu: "/web/repo" },
      },

      {
        path: "/web/repo/repo/:trainId",
        component: () => import("@/views/web/repo/result"),
        name: "TrainResult",
        meta: { title: "训练结果", noCache: true, activeMenu: "/web/repo" },
      },
    ],
  },

  courseRouter,

  // { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
